#include<iostream>
#include<vector>
#include<unordered_map>
using namespace std;

class Solution {
public:
	vector<int> topKFrequent(vector<int>& nums, int k) {
		unordered_map<int, int> map;
		for (int i = 0; i < nums.size(); i++) {
			map[nums[i]]++;
		}
		vector<int> res;
		for (int i = 0; i < k; i++) {
			unordered_map<int,int> ::iterator maxiter;
			int max = -1;
			for (auto it=map.begin(); it != map.end(); it++) {
				if (it->second > max) {
					max = it->second;
					maxiter = it;
				}
			}
			res.push_back(maxiter->first);
			map.erase(maxiter);
		}
		return res;
	}
};

void main() {
	vector<int> nums = { 1, 1, 1, 2, 2, 3 };
	int k = 2;
	Solution s;
	s.topKFrequent(nums, k);
}